home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Mixed Mode Maddness / Emulator / Unused / bcd.c next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  831 b   |  53 lines

  1. #include "bcd.h"
  2.  
  3. //////////////////////////////////////////////
  4. //
  5. //    NormalizeBCD
  6. //
  7. //////////////////////////////////////////////
  8. UInt8 NormalizeBCD(UInt8 theNum)
  9. {
  10.     UInt8 low, hi;
  11.     
  12.     low = theNum & 0x0F;
  13.     hi = theNum & 0xF0;
  14.  
  15.     if (low > 0x09) {
  16.         low -= 0x0A;
  17.         hi += 0x10;
  18.     }
  19.     if (hi > 0x90) {
  20.         hi -= 0xA0;
  21.     }
  22.     return hi | low;
  23. }
  24.  
  25. //////////////////////////////////////////////
  26. //
  27. //    ConvertNumToBCD
  28. //
  29. //////////////////////////////////////////////
  30. UInt8 ConvertNumToBCD(UInt8 theNum)
  31. {
  32.     UInt8 low, hi;
  33.     
  34.     hi = theNum >> 4;
  35.     low = theNum - (hi << 4);
  36.     hi << 4;
  37.     return hi | low;
  38. }
  39.  
  40. //////////////////////////////////////////////
  41. //
  42. //    ConvertBCDToNum
  43. //
  44. //////////////////////////////////////////////
  45. UInt8 ConvertBCDToNum(UInt8 theNum)
  46. {
  47.     UInt8 low, hi;
  48.     
  49.     low = theNum & 0x0F;
  50.     hi = theNum & 0xF0;
  51.     return hi*10 + low;
  52. }
  53.